﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using V = Science.Mathematics.VectorCalculus;

namespace VectorCalculus5Ed.Chapter2.Section6
{
    public class Example01
    {
        public Example01()
		{
		}
		private string result;
		public string Result
		{
			get{return result;}
		}
        public void Compute()
        {
            V.Function.ToLastType<double[], double> f
                = new V.Function.ToLastType<double[], double>(func);
            double[] at = {2.5,4.5,1.5 };
            V.Gradient delf = new V.Gradient(f,at);
            delf.Compute();
            result += delf.Result[0].ToString() + "  ";
            result += delf.Result[1].ToString() + "  ";
            result += delf.Result[2].ToString() + "\r\n";

            result += (delf.Result[0]*delf.Result[0] +
                delf.Result[1]*delf.Result[1]+
                    delf.Result[2]*delf.Result[2]).ToString() + "\r\n";
        }
        private double func(double[] x)
        {
            return Math.Sqrt(x[0] * x[0] + x[1] * x[1] + x[2] * x[2]);
        }
    }
}
// 0.466252404120089  0.839254327415347  0.279751442472656
// 0.999999999998682

   